package eiisan.nio;

import java.nio.IntBuffer;
import java.security.SecureRandom;

/**
 * @description: Nio 存/读数据
 * @author: eii
 * @time: 2020/7/12 5:22 下午
 */
public class NioTest1 {

    public static void main(String[] args) {
        IntBuffer buffer = IntBuffer.allocate(10);

        for (int i = 0; i < buffer.capacity(); i++) {
            int randomNunber = new SecureRandom().nextInt(20);
            buffer.put(randomNunber);
        }
        buffer.flip();//此处必须要调用buffer的flip方法，  实现读 ，写 转换

        while (buffer.hasRemaining()){
            System.out.println(buffer.get());
        }

    }

}
